<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>新增</title>
    <style>
        .error{
            color: red;
        }
    </style>
    <script src="${pageContext.request.contextPath}/statics/jquery-1.8.3.min.js"></script>
</head>
<body>
<h1>水果新增</h1>
<form method="post" action="add" enctype="multipart/form-data">
    <table>
        <tr>
            <td>类别:</td>
            <td>
                <input type="text" name="type" value="${fruit.type}" onblur="checkType(this)"><span class="error">${typeError}</span>
            </td>
        </tr>
        <tr>
            <td>品种:</td>
            <td><input type="text" name="breed" value="${fruit.breed}"><span class="error">${breedError}</span></td>
        </tr>
        <tr>
            <td>产地:</td>
            <td><input type="text" name="area" value="${fruit.area}"><span class="error">${areaError}</span></td>
        </tr>
        <tr>
            <td>简介:</td>
            <td><input type="text" name="brief" value="${fruit.brief}"><span class="error">${briefError}</span></td>
        </tr>
        <tr>
            <td>采摘日期:</td>

            <td><input type="text" name="dataTime" value="<fmt:formatDate value="${fruit.dataTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"><span class="error">${dataTimeError}</span></td>
        </tr>
        <tr>
            <td>图片:</td>

            <td>
                <input type="file" name="filePic">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <a href="list">返回</a>
                <input type="submit">
            </td>
        </tr>
    </table>
</form>

<script>
    function checkType(el) {
        // 'type='+value
        $.get('checkType',{type:el.value},function (data) {
            if(data=='true'){
                $(el).next('span').html('类型已存在');
            }else {
                $(el).next('span').html('');
            }
        });
    }
</script>
</body>
</html>
